package com.cam.framework.utils;

import java.io.Serializable;
import java.util.HashMap;

public class RestResult extends HashMap<String, Object> implements Serializable {

    public RestResult() {

    }

    /*
     * 重写 hashmap put 方法，方便实现链式操作
     * */
    @Override
    public RestResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public void setMessage(String message) {
        this.put("message", message);
    }

    public static RestResult success() {
        return new RestResult();
    }

    public static RestResult success(String message) {
        RestResult restResult = RestResult.success();
        restResult.setMessage(message);
        return restResult;
    }

    public static RestResult error() {
        return new RestResult();
    }

    public static RestResult error(String message) {
        RestResult restResult = RestResult.error();
        restResult.setMessage(message);
        return restResult;
    }

    public RestResult data(Object data) {
        return this.put("data", data);
    }
}
